/**
 * A Simple IIFE Module Solution.
 * @author urain39 <urain39@qq.com>
 */

/** @module */
(function (global) {
	function defineModule() {
		var name,
			description,
			module;

		switch (arguments.length) {
			case 2:
				name = arguments[0];
				factory = arguments[1];
				break;
			case 3:
				name = arguments[0];
				description = arguments[1];
				factory = arguments[2];
				break;
			default:
				throw new Error("Invalid arguments");
				break;
		}

		var module = global[name];

		if (!(module && module.__IS_IMD)) {
			module = factory() || {};

			if (description)
				module.__DESCRIPTION = description;

			module.__IS_IMD = true;
			global[name] = module;
		}
	}

	defineModule(
		"IMD",
		"A Simple IIFE Module Solution.",
		function() {
			return { define: defineModule };
		}
	);
})(this);
